﻿using System.Collections.Generic;
using Titul.Help.Models;
using System.Linq;
using Neo4j.DataProvider;

namespace Titul.Help.Storages
{
    public class VersionStorage : SimpleStorage<Version>
    {
        private Neo4jDataProvider<Version> _provider;
        public VersionStorage()
        {
            _provider = new Neo4j.DataProvider.Neo4jDataProvider<Version>(this.Client);
        }

        public override IEnumerable<Version> All
        {
            get
            {
                return _provider.All;
            }
        }

        public override Version Create(Version version)
        {
            var model = _provider.CreateIfNotExist(version, "Number");
            return model;
        }

        public override Version Single(int id)
        {
            var model = _provider.Single(id);
            return model;
        }

        public override Version Single(string seoUrl)
        {
            var model = _provider.GetByPropertyValue("SeoUrl", seoUrl);
            return model;
        }

        public override Version Edit(Version version)
        {
            if (version.Id != 0)
                _provider.Update(version);
            return version;
        }
    }
}
